package com.arcbbs.controller;

import com.arcbbs.constant.BaseConstant;
import com.arcbbs.entity.UserInfo;
import com.arcbbs.mapper.UserInfoMapper;
import com.arcbbs.result.Result;
import com.arcbbs.service.UserInfoService;
import com.arcbbs.utils.CreateImageCode;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@RestController
@Api(tags = "测试接口")
public class TestController {
    @Resource
private UserInfoService userInfoService;
    @RequestMapping("/test")
    public String test(){
        return "hello";
    }
    @GetMapping("/checkcode")
    public void checkcode(HttpServletResponse response, HttpSession session,Integer type) throws IOException {
        CreateImageCode vcode=new CreateImageCode(130,38,10);
        response.setHeader("Pragma","no-cache");
        response.setHeader("Cache-Control","no-cache");
        //生效时间
        response.setDateHeader("Expires",0);
        response.setContentType("image/jpeg");
        String code=vcode.getCode();
        if(type == null|| type == 0){
            //登录注册
            session.setAttribute(BaseConstant.CHECK_CODE_KEY,code);
        }else{
            session.setAttribute(BaseConstant.CHECK_CODE_KEY_EMAIL,code);
        }
        vcode.write(response.getOutputStream());

    }
}
